/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package neuralnetwork;

import java.io.FileNotFoundException;
import java.io.IOException;
import org.neuroph.core.learning.DataSet;
import org.neuroph.util.TrainingSetImport;
import org.neuroph.util.TransferFunctionType;

/**
 *
 * @author Rosana
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        // setup
        String trainingSetFileName = "trainingSet.txt";
        String testingSetFileName = "testingSet.txt";
        int inputsCount = 41;
        int outputsCount = 1;

        // create training set
        DataSet trainingSet = null;
        try {
            trainingSet = TrainingSetImport.importFromFile(trainingSetFileName, inputsCount, outputsCount, ",");
        } catch (FileNotFoundException ex) {
            System.out.println("TrainingSet file not found!");
        } catch (IOException | NumberFormatException ex) {
            System.out.println("Error reading file or bad number format!");
            System.out.println("Using COMA ',' separator?");
        }

        /* create testing set
        DataSet testingSet = null;
        try {
            testingSet = TrainingSetImport.importFromFile(testingSetFileName, inputsCount, outputsCount, ",");
        } catch (FileNotFoundException ex) {
            System.out.println("TestingSet file not found!");
        } catch (IOException | NumberFormatException ex) {
            System.out.println("Error reading file or bad number format!");
            System.out.println("Using COMA ',' separator?");
        }
        */
        trainingSet.normalize();
       // testingSet.normalize();
       // trainingSet.saveAsTxt("normalized.txt", ",");
        DataSet[] c = trainingSet.createTrainingAndTestSubsets(20, 80);
       trainingSet=c[0];
      DataSet testingSet=c[1];
        
       
        
        // neural net
        NeuralNetwork neuralNet = new NeuralNetwork(
                inputsCount,
                30,
                outputsCount,
                TransferFunctionType.TANH);
        
        // neural net setup
        neuralNet.setLearningRate(0.8188976377952756);
        neuralNet.setMomentum(0.7165354330708661);
        neuralNet.setMaxError(0.009);

        // training Step
        neuralNet.learn(trainingSet);
        
        // testing result
        double totalError = 100 * neuralNet.test(testingSet) / testingSet.size();
        System.out.println("Erros: " + totalError + "%");
    }

}
